#include"Sem.hpp"
#include<ctime>

int main()
{
    SemBuilderBuilder sb;
    auto fsem = sb.SetVal(1).build(BUILD_SEM,1);

    srand(time(0)*getpid());
    pid_t pid = fork();

    if(pid == 0)
    {
        //child
       auto csem = sb.build(GET_SEM); //
       while(true)
       {
        csem->P();
        printf("C");
        usleep(rand()%95270);
        fflush(stdout);
        printf("C");
        usleep(rand()%43990);
        fflush(stdout);
        csem->V();
       }
    }

    //parent
    while(true)
    {
      fsem->P();
      printf("F");
      usleep(rand()%95270);
      fflush(stdout);
      printf("F");
      usleep(rand()%43990);
      fflush(stdout);
      fsem->V();
    }

    return 0;
}